// The form contains fields for many pagiantion optiosn so you can 
// quickly see the resuluts of the different options.
// This function creates an option object for the pagination function.
// This will be be unnecessary in your application where you just set
// the options once.
$(function() {
		var items_on_page = 20;
		var pages_step = 5;
		
		get_data(1, 20);
		var url = location.href;
		var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
		var paraObj = {}
		for (i=0; j=paraString[i]; i++){
			paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
		}
		var univ_id = paraObj["univ_id"];
		var cat_id = paraObj["cat_id"];
		if(typeof(univ_id)=="undefined"){
			univ_id = "-1";
		}
		if(typeof(cat_id)=="undefined"){
			cat_id = "-1";
		}
		$.ajax({
			type: "POST",
			url: "/topic/topic_total",
			data: {
			univ_id: univ_id,
			cat_id: cat_id,	
			type: "get"},
			success: function(total)
			{
				$("#paging").jpaging({
					all_items_num: total,
					callback: get_data,
					items_on_page: items_on_page,
					pages_step: pages_step
				});
			}
		});

		function get_data(start_index, end_index){
			var url = location.href;
			var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
			var paraObj = {}
			for (i=0; j=paraString[i]; i++){
				paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
			}
			var univ_id = paraObj["univ_id"];
			var cat_id = paraObj["cat_id"];
			if(typeof(univ_id)=="undefined"){
				univ_id = "-1";
			}
			if(typeof(cat_id)=="undefined"){
				cat_id = "-1";
			}
			start_index = start_index - 1;
			end_index = end_index - 1;
			$.ajax({
				type: "POST",
				url: "/topic/topic_paging",            
				data: {start_index: start_index,
				end_index: end_index,
				univ_id: univ_id,
				cat_id: cat_id,	
				type: "get"},
				success: function(html)
				{                  
					$("#demo_tbl").html(html);
					 $('html, body').animate({ scrollTop: 0 }, 'slow');
					$.prettyDate.now = function() {
						return new Date();
					}
					$(".prettyDate").prettyDate();

				}
			});			
		}

});
